// 源插件
import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import moment from 'moment';
import router from 'umi/router';

// 视图插件
import {
  Spin,
  Row,
  Col,
  Card,
  Form,
  Input,
  Select,
  Icon,
  Button,
  Dropdown,
  Menu,
  InputNumber,
  DatePicker,
  Modal,
  message,
  Badge,
  Divider,
  Steps,
  Radio,
  Upload,
} from 'antd';

// 外部组件
import StandardTable from '@/components/StandardTable';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';

// css OR less预编译器

// 图片

const FormItem = Form.Item;

/**
 *  Created by xjc on 2019/8/15
 *  Describe:数据连接
 */

@connect(({ positionrui, loading }) => ({
  positionrui,
  loading: loading.models.positionruiRule,
}))
@Form.create()
class StocksTableDetail extends PureComponent {
  componentWillMount() {}

  /**
   *  Created by xjc on 2019/8/15
   *  Describe:当前状态
   */

  state = {};

  onChange = e => {};

  okHandle() {
    this.props.form.validateFields((err, values) => {
      if (!err) {
        const { record, dispatch } = this.props;
        const payload = []; /* ([1-9]?\d|100)$ */
        if (values.number1 !== 0) {
          payload.push({
            costprice: record.costprice,
            stock: record.stock,
            groupid: 1,
            stockbelongnumber: values.number1,
            id: values.id,
          });
        }
        if (values.number2 !== 0) {
          payload.push({
            costprice: record.costprice,
            stock: record.stock,
            groupid: 2,
            stockbelongnumber: values.number2,
            id: values.id,
          });
        }
        if (values.number3 !== 0) {
          payload.push({
            costprice: record.costprice,
            stock: record.stock,
            groupid: 3,
            stockbelongnumber: values.number3,
            id: values.id,
          });
        }
        dispatch({
          type: 'positionrui/SlitPositionStocks',
          payload,
          callback: () => {
            this.props.closeRecord();
          },
        });
      }
    });
  }

  cancelHandle() {
    this.props.closeRecord();
  }

  render() {
    const {} = this.state;
    const { record, form, StocksDetailVisible } = this.props;
    const { getFieldDecorator } = form;

    return (
      <Modal
        destroyOnClose
        title="条目操作"
        visible={StocksDetailVisible}
        centered
        onOk={this.okHandle.bind(this)}
        onCancel={this.cancelHandle.bind(this)}
      >
        <Form onSubmit={this.handleSearch} style={{ overflowY: 'scroll' }}>
          <FormItem label="ID" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('id', { initialValue: record.id })(
              <Input readOnly style={{ width: '85%' }} placeholder="ID" />
            )}
          </FormItem>

          <FormItem label="总量" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('amount', { initialValue: record.stocknumber })(
              <Input readOnly style={{ width: '85%' }} placeholder="总量" />
            )}
          </FormItem>

          <FormItem label="金融团队管理" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('number1', {
              initialValue:
                record.sourceperson === '金融团队管理'
                  ? record.groupname === null
                    ? typeof record.stocknumber === 'number' ||
                      typeof record.stocknumber === 'string'
                      ? record.stocknumber
                      : 0
                    : typeof record.stockbelongnumber === 'number' ||
                      typeof record.stockbelongnumber === 'string'
                    ? record.stockbelongnumber
                    : 0
                  : 0,
            })(
              <InputNumber
                style={{ width: '85%' }}
                placeholder="金融团队管理"
                min={0}
                formatter={value => `${value}`.replace(/[^0-9]/gi, '')}
              />
            )}
          </FormItem>

          <FormItem label="傅总管理" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('number2', {
              initialValue:
                record.sourceperson === '傅总管理'
                  ? record.groupname === null
                    ? typeof record.stocknumber === 'number' ||
                      typeof record.stocknumber === 'string'
                      ? record.stocknumber
                      : 0
                    : typeof record.stockbelongnumber === 'number' ||
                      typeof record.stockbelongnumber === 'string'
                    ? record.stockbelongnumber
                    : 0
                  : 0,
            })(
              <InputNumber
                style={{ width: '85%' }}
                placeholder="傅总管理"
                min={0}
                formatter={value => `${value}`.replace(/[^0-9]/gi, '')}
              />
            )}
          </FormItem>

          <FormItem label="郭老师管理" labelCol={{ span: 8 }} wrapperCol={{ span: 15 }}>
            {getFieldDecorator('number3', {
              initialValue:
                record.sourceperson === '郭老师管理'
                  ? record.groupname === null
                    ? typeof record.stocknumber === 'number' ||
                      typeof record.stocknumber === 'string'
                      ? record.stocknumber
                      : 0
                    : typeof record.stockbelongnumber === 'number' ||
                      typeof record.stockbelongnumber === 'string'
                    ? record.stockbelongnumber
                    : 0
                  : 0,
            })(
              <InputNumber
                style={{ width: '85%' }}
                placeholder="郭老师管理"
                min={0}
                formatter={value => `${value}`.replace(/[^0-9]/gi, '')}
              />
            )}
          </FormItem>
        </Form>
      </Modal>
    );
  }

  componentDidMount() {}

  componentWillUnmount() {}
}

export default StocksTableDetail;
